<?php
/**
 * User: xzq
 * Date: 2018/8/9
 * Time: 10:22
 */

namespace app\wechat\home;
use app\common\controller\Common;
use app\wechat\model\Notice;

class Notices extends Common{
    /**
     * 首页公告
     * @return mixed
     */
    public function index(){
        $notice = new Notice();
        $data['status'] = 1;
        $list = $notice->getOne($data);
        if (!$list){
            return show(0,'暂无公告');
        }
        $list['ctime'] = date('Y-m-d H:i',$list['ctime']);
        return show(1,'成功',$list);
    }

    /**
     * 公告列表
     * @return bool|false|static[]
     */
    public function allList(){
        $page = input('post.page/d');
        $notice = new Notice();
        $data['status'] = 1;
        $page = !empty($page) ? $page : 1;
        $res = $notice->getAll($data,$page);
        $list = $res['data'];
        foreach ($list as $key => $value){
            $list[$key]['ctime'] = date('Y-m-d H:i',$value['ctime']);
        }
        $res['data'] = $list;
        return $res;
    }
    /**
     * 公告详情
     * @return bool|false|static[]
     */
    public function detail(){
        $id = input('post.id/d');
        $notice = new Notice();
        $data['id'] = $id;
        $list = $notice->getOne($data);
        if (!$list){
            return show(0,'该公告不存在');
        }
        $list['ctime'] = date('Y-m-d H:i',$list['ctime']);
        return show(1,'成功',$list);
    }
}